// pages/jump/jump.js
Page({

  /**
   * 页面的初始数据
   */
  data: {
    service_name:'',
    service_phone:'',
    distance:'',
    isWork:'',
    service_introduce:'',
    self_introduction:'',
    picPath: ''
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {

  },
  ChooseImag: function (e) {
    var that = this
    wx.chooseImage({
      count: 1,
      sourceType: 'album',
      sizeType: ['compressed'],
      success(res) {
        that.setData({
          tempFilePaths: res.tempFilePaths[0]

        })
        setTimeout(function (e) {
          wx.showLoading({
            title: '正在上传图片...',
          })
        }, 500)
        let MyFile = new wx.BaaS.File()
        let fileParams = {
          filePath: that.data.tempFilePaths
        }
        let metaData = {
          categoryName: 'SDK',
          categoryName: 'image'
        }

        MyFile.upload(fileParams, metaData).then(res => {
          // 上传成功
          console.log(res)
          that.setData({
            avatarUrl: res.data.path,
            picPath: res.data.path,
            pic_id: res.data.file.id
          })
          wx.hideLoading()
          console.log(that.data.avatarUrl)
          // let tableName = 'service_items'
          // let recordID = wx.getStorageSync('id') // 数据行 id
          // let Product = new wx.BaaS.TableObject(tableName)
          // let product = Product.getWithoutData(recordID)

          // product.set('fukuanma', that.data.avatarUrl);
          // wx.setStorageSync('isInformation2', true)
          // product.update().then(res => {
          //     console.log(res)
          // }, err => {
          //     // err
          // })
        }, err => {
          // HError 对象
          // this.hideLoading()
          wx.showModal({
            title: '上传失败',
            content: '请等待三秒后重新点击<提交>',
            showCancel: false,
            success: res => {
              if (res.confirm) {
                that.setData({
                  submitDisabled: true
                })
                setTimeout(function () {
                  that.setData({
                    submitDisabled: false
                  })
                }, 5000)
              }
            }
          })
        })

      }
    })
  },
  deletePic: function () {
    let MyFile = new wx.BaaS.File()

    MyFile.delete(this.data.pic_id).then()
    this.setData({
      picPath: ''
    })

  },
  submit: function () {
    // 向 tableName 为 'product' 的数据表插入一条记录
    let tableName = 'service'
    let Product = new wx.BaaS.TableObject(tableName)
    let product = Product.create()

    // 设置方式一
    let apple = {
      service_img: this.data.picPath,
      service_introduce: this.data.service_introduce,
      service_phone: this.data.service_phone,
      isWork: 1,
      service_name: this.data.service_name,
      self_introduction:this.data.self_introduction
    }
    console.log(apple)
    product.set(apple).save().then(res => {
      // success
      console.log(res)
    }, err => {
      //err 为 HError 对象
    })
  },
  jump() {
    wx.navigateTo({
      url: '../search/search'

    })
  },
  setMC:function(e){
    this.setData({
      service_name:e.detail.value
    })
    console.log(this.data.service_name)
  },
  setDH:function(e){
    this.setData({
      service_phone:e.detail.value
    })
    console.log(this.data.service_phone)
  },
  setWZ:function(e){
    this.setData({
      distance:e.detail.value
    })
    console.log(this.data.distance)
  },
  setGZ:function(e){
    this.setData({
     isWork:e.detail.value
    })
    console.log(this.data.isWork)
  },
  setJC:function(e){
    this.setData({
      service_introduce:e.detail.value
    })
    console.log(this.data.service_introduce)
  },
  setMS:function(e){
    this.setData({
      self_introduction:e.detail.value
    })
    console.log(this.data.self_introduction)
  },
})